// 路由配置信息
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/pay'
import PaySuccess from '@/pages/paysuccess'
import Center from '@/pages/Center'
// 二级路由
import myOrder from '@/pages/Center/myOrder'
import groupOrder from '@/pages/Center/groupOrder'

export default [
    {
        path: '/home',
        component: Home,
        meta: { show: true }
    },
    {
        path: '/login',
        component: Login,
        meta: { show: false }
    },
    {
        path: '/register',
        component: Register,
        meta: { show: false }
    },
    {
        path: '/search/:keyword?',
        component: Search,
        meta: { show: true },
        name: "search",
    },
    // 路由重定向
    {
        path: '*',
        redirect: '/home'
    },
    {
        path: '/detail/:skuId',
        component: Detail,
        meta: { show: true }
    },
    {
        path: '/addcartsuccess',
        name: 'addcartsuccess',
        component: AddCartSuccess,
        meta: { show: true }
    },
    {
        path: '/shopcart',
        component: ShopCart,
        meta: { show: true }
    },
    {
        path: '/trade',
        component: Trade,
        meta: { show: true },
        // 路由独享守卫
        beforeEnter:(to,from,next)=>{
            if(from.path == '/shopcart'){
                next()
            }else{
                // 不是从shopcart来的停留在原页面
                next(false)
            }
        }
    },
    {
        path: '/pay',
        component: Pay,
        meta: { show: true },
        // 路由独享守卫
        beforeEnter:(to,from,next)=>{
            if(from.path == '/trade'){
                next()
            }else{
                // 不是从trade来的停留在原页面
                next(false)
            }
        }
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        meta: { show: true },
    },
    {
        path: '/center',
        component: Center,
        meta: { show: true },
        // 路由重定向
        redirect:'/center/myOrder',
        children:[
            {
                path:'/center/myOrder',
                component:myOrder,
            },
            {
                path:'/center/groupOrder',
                component:groupOrder
            },
        ]
    }
]